﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Vehicle.Web.Pages.Post
{
    /// <summary>
    /// Copyright (C) M-Tear团队
    /// 文 件 名：Post_Edit.aspx.cs
    /// 版    本：v1.00.0000
    /// 创建标识：2009-09-03   Created by 孙成杰 V1.00.0000
    /// 功能说明：公告编辑页面类
    /// 注意事项：无
    /// 
    /// 更新记录：
    /// 
    /// </summary>
    public partial class Post_Edit : Component.PageBase
    {
        
        #region ---基本变量实例化---
        BLL.Post b_Post = new BLL.Post();//实例化Post逻辑层
        BLL.Log b_Log = new Vehicle.BLL.Log();
        #endregion

        #region---基本操作---
        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PostDataBind();//绑定数据
            }
        }
        /// <summary>
        /// 数据更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Edit_Click(object sender, EventArgs e)
        {
            b_Post.Update(new Model.PostInfo(Vehicle.Common.TextHelper.StringToInt(hf_P_ID.Value), txt_P_Title.Text.Trim(), txt_P_Name.Text.Trim(), Vehicle.Common.TextHelper.CheckStr(txt_P_Note.Text)));//修改数据
            b_Log.Add(new Vehicle.Model.LogInfo(session_ID, DateTime.Now, "成功修改标题目为《" +txt_P_Title.Text.Trim() + "》的公告信息"));//添加日志
            Vehicle.Common.MessageHelper.AlertRedirect("修改资料成功", "Main.aspx");
        }
        /// <summary>
        /// 公告数据绑定
        /// </summary>
        public void PostDataBind()
        {
            if (Request.QueryString["id"] != null)
            {
                try
                {
                    DataTable dt = b_Post.GetModel(new Model.ComponentsInfo("Post", "P_ID", Request.QueryString["id"].ToString(), "P_ID"));
                    txt_P_Title.Text = dt.Rows[0]["P_Title"].ToString();//公告标题
                    txt_P_Name.Text = dt.Rows[0]["P_Name"].ToString();//公告作者
                    txt_P_Note.Text = dt.Rows[0]["P_Note"].ToString();//公告内容
                    hf_P_ID.Value = Request.QueryString["id"].ToString();//公告ID隐藏值
                }
                catch
                {
                    Vehicle.Common.MessageHelper.AlertBack("操作错误!");
                }
            }
            else
            {
                Vehicle.Common.MessageHelper.AlertBack("操作错误!");
            }
        }
        #endregion
    }
}
